import click
import platform

from tools.generator.sdfgenerator import SDFGenerator


@click.command(
    name="gen",
    help="Automatically generate a Slice Definition File (SDF) for an openEuler package.",
)
@click.option(
    "-r",
    "--release",
    required=True,
    help="This decides which openEuler release you will use, such as `openEuler-24.03-LTS-SP1`.",
)
@click.option(
    "-a",
    "--arch",
    default=None,
    help="The architecture. If not provided, it will be auto-detected from the host machine.",
)
@click.option(
    "-o", "--output", default=".", help="The directory to save the generated SDF file."
)
@click.option(
    "-p",
    "--package",
    required=True,
    help="The name of the RPM package to generate an SDF for (e.g., 'attr').",
)
def gen(release, arch, output, package):
    """
    CLI command to orchestrate SDF generation.
    """
    if not arch:
        arch = platform.machine()
        click.echo(f"Architecture not specified, auto-detected: {arch}")

    click.echo(
        f"Starting SDF generation for '{package}' on openEuler-{release} ({arch})..."
    )

    generator = SDFGenerator(release=release, arch=arch, output=output, package=package)
    generator.gen()
